﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DeviceManager.DataAccessLayer;
using DeviceManager.BusinessLogicLayer;

namespace DeviceManagementIT.DevicesManager.Unit
{
    public partial class frmListUnit : DevExpress.XtraEditors.XtraForm
    {
        UnitBllOperation unitbll = new UnitBllOperation();
        public frmListUnit()
        {
            InitializeComponent();
        }

        private void ListUnit_Load(object sender, EventArgs e)
        {
            btnLamTuoi.PerformClick();
        }

        private void btnLamTuoi_Click(object sender, EventArgs e)
        {
            List<DONVITINH> listunit = unitbll.GetRecordUnit(new DONVITINH());
            gdCDanhsachdvt.DataSource = listunit;
            grViewUnit.Columns[1].Caption = "Tên Đơn Vị Tính";
            grViewUnit.Columns[2].Caption = "Diễn Giải";
            grViewUnit.Columns[0].Visible = false;
            grViewUnit.Columns[3].Visible = false;
            grViewUnit.Columns[4].Visible = false;
        }

        private void btnDeleteUnit_Click(object sender, EventArgs e)
        {
            DONVITINH unitDvt = new DONVITINH();
            if (grViewUnit.DataRowCount != 0)
            {
                unitDvt.DVTIT = int.Parse(grViewUnit.GetFocusedRowCellDisplayText("DVTIT"));
                unitDvt.TenDVT = grViewUnit.GetFocusedRowCellDisplayText("TenDVT");
                unitDvt.DienGiai = grViewUnit.GetFocusedRowCellDisplayText("DienGiai");
                string message = unitbll.DeleteRecordUnit(unitDvt);
                MessageBox.Show(message, "Message");
                btnLamTuoi.PerformClick();
            }
        }
    }
}